﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using WhittleList.Bll;

namespace WhittleList.Tests.Bll
{
    [TestClass]
    public class SectionTests
    {

        [TestMethod]
        public void IsValid_False_WhenGetRuleViolationsNotEmpty()
        {

            var tmp = new Moq.Mock<Section>();
            tmp.Setup(x => x.GetRuleViolations()).Returns(new RuleViolation[] { new RuleViolation("Test") });
            Assert.IsFalse(tmp.Object.IsValid);
        }

        [TestMethod]
        public void IsValid_True_WhenGetRuleViolationsEmpty()
        {

            var tmp = new Moq.Mock<Section>();
            tmp.Setup(x => x.GetRuleViolations()).Returns(new RuleViolation[0]);
            Assert.IsTrue(tmp.Object.IsValid);
        }

        [TestMethod]
        public void Name_IsRequiredTest()
        {
            var tmp = new Section();
            Assert.AreEqual(1, tmp.GetRuleViolations().Where(x => x.PropertyName == "Name").Count());
            tmp.Name = "Test";
            Assert.AreEqual(0, tmp.GetRuleViolations().Where(x => x.PropertyName == "Name").Count());
        }

        [TestMethod]
        public void ProjectId_IsRequiredTest()
        {
            var tmp = new Section();
            Assert.AreEqual(1, tmp.GetRuleViolations().Where(x => x.PropertyName == "ProjectId").Count());
            tmp.ProjectId = 1;
            Assert.AreEqual(0, tmp.GetRuleViolations().Where(x => x.PropertyName == "ProjectId").Count());
        }
    }
}
